package org.tim.es.session;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.tim.es.ElasticsearchConstants;

import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
@Document(indexName = UserPrivateSession.INDEX_NAME, type = "_doc")
public class UserPrivateSession {
    public static final String INDEX_NAME = ElasticsearchConstants.INDEX_PREFIX + "privatesession";

    @Id
    @Schema(description = "私聊会话 ID")
    @Field(type = FieldType.Keyword)
    private String id;

    @Field(type = FieldType.Keyword)
    @Schema(description = "发送者 ID")
    private String fromUserId;

    @Field(type = FieldType.Keyword)
    @Schema(description = "发送者名称")
    private String fromUserName;

    @Field(type = FieldType.Text)
    @Schema(description = "发送者头像")
    private String fromIconUrl;

    @Field(type = FieldType.Keyword)
    @Schema(description = "接收者 ID")
    private String toUserId;

    @Field(type = FieldType.Keyword)
    @Schema(description = "接收者名称")
    private String toUserName;

    @Field(type = FieldType.Text)
    @Schema(description = "接受者头像")
    private String toIconUrl;

    @Field(type = FieldType.Long)
    @Schema(description = "当前会话未读数")
    private Long unreadCnt;

    @Field(type = FieldType.Text)
    @Schema(description = "最后的会话内容")
    private String laseSessionMessage;

    @Field(type = FieldType.Boolean)
    @Schema(description = "会话是否从列表移除")
    private boolean delete;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    @Schema(description = "最近会话时间")
    private LocalDateTime lastSessionAt;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    @Schema(description = "会话创建时间")
    private LocalDateTime createdAt;
}
